package com.db.controller;

import com.db.common.pojo.JsonResult;
import com.db.common.pojo.TreeNode;
import com.db.pojo.SysMenu;
import com.db.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu/")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @RequestMapping("doFindObjects")
    public JsonResult doFindObjects() {
        List<SysMenu> list = sysMenuService.findObjects();
        return new JsonResult(list);
    }

    //doDeleteObject
    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id) {
        sysMenuService.deleteById(id);
        return new JsonResult("delete ok");
    }

    @RequestMapping("doFindZtreeMenuNodes")
    public JsonResult doFindZtreeMenuNodes() {
        List<TreeNode> list = sysMenuService.findTree();
        return new JsonResult(list);
    }

    //doSaveObject
    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(SysMenu sysMenu) {
        sysMenuService.insertObject(sysMenu);
        return new JsonResult("insert ok");
    }

    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(SysMenu sysMenu) {
        sysMenuService.updateObject(sysMenu);
        return new JsonResult("update ok");
    }
}
